package ch.ifage.business.dom;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;




/**
 * 
 * @author Christian
 *
 */
public class Workflows  implements Serializable {

	/**
	 * serial uid.
	 */
	private static final long serialVersionUID = 5218175044145633306L;
	
	/**
	 * Liste des worflows.
	 */
	private List<Workflow> list = null;

	/**
	 * constructeur.
	 */
	public Workflows() {
		list = new ArrayList<Workflow>();
	}
	
	/**
	 * List of all workflows.
	 * @return the complete list of workflows.
	 */
	public final List<Workflow> getList() {
		return list;
	}
	
	/** 
	 * Subset of the workflows that contains a given string in the log.
	 * @param subStringOfLog string to find.
	 * @return List<Workflow> subset filtered.
	 */
	public final List<Workflow> getSubSetList(final String subStringOfLog) {
		List<Workflow> subSetList = new ArrayList<Workflow>();
		String subStringOfLogLc = subStringOfLog.toLowerCase();
		
		for (Iterator<Workflow> i = this.list.iterator(); i.hasNext();) {
			Workflow w = (Workflow) i.next();
			if (w.logContainsSubString(subStringOfLogLc)) {
				subSetList.add(w);
			}
		}
		return subSetList; 	
	}
	
	/** 
	 * Step that contains a given string in the log.
	 * @param subStringOfLog string to find.
	 * @return Step first step found.
	 * Used by the SOAP server.
	 */
	public final Step getStepLogContains(final String subStringOfLog) {
		String subStringOfLogLc = subStringOfLog.toLowerCase();
		
		for (Iterator<Workflow> i = this.list.iterator(); i.hasNext();) {
			Workflow w = (Workflow) i.next();
			Step stepFound = w.getStepLogContainsSubString(subStringOfLogLc);
			if (stepFound != null) {
				return stepFound;
			}
		}
		return null; 	
	}



	/**
	 * Add workflow to the set of workflows.
	 * @param workflow the workflow to add.
	 */
	public final void add(final Workflow workflow) {
		list.add(workflow);
	}


	/* (non-Javadoc)
	 */
	@Override
	public final String toString() {
		return "Workflows [list=" + list + "]";
	}
	

}